package com.lysj.admin.master.bussiness.company.invoice.controller;

import com.lysj.admin.master.bussiness.company.company.dto.CompanyNormalQueryDto;
import com.lysj.admin.master.bussiness.company.invoice.domain.InvoiceRecipient;
import com.lysj.admin.master.bussiness.company.invoice.mapper.InvoiceRecipientMapper;
import com.lysj.admin.master.bussiness.company.invoice.service.InvoiceRecipientService;
import com.lysj.admin.master.common.CommonConstant;
import com.lysj.admin.master.common.annotation.LogicalDel;
import com.lysj.admin.master.common.annotation.MyList;
import com.lysj.admin.master.common.annotation.Save;
import com.lysj.admin.master.common.annotation.Update;
import com.lysj.admin.master.common.spring.mpbase.MyController;
import com.lysj.admin.master.common.spring.mpbase.MyService;
import com.lysj.admin.master.common.spring.pagination.PageRequestDTO;
import com.lysj.admin.master.common.web.Resp;
import com.lysj.admin.master.common.web.RespUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @author Created by drj on 2020-01-07 11:27
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/company/invoice_recipient")
public class InvoiceRecipientController extends MyController<InvoiceRecipientMapper, InvoiceRecipient, PageRequestDTO> {

    @Resource
    private InvoiceRecipientService invoiceRecipientService;

    @Override
    public MyService<InvoiceRecipientMapper, InvoiceRecipient> getService() {
        return invoiceRecipientService;
    }

    @MyList
    public Resp list(CompanyNormalQueryDto condition) {
        //获取当前登录用工企业
        String companyId = getJwtProperty(CommonConstant.COMPANY_ID_NAME);
        condition.setCompanyId(companyId);
        return super.list(condition);
    }

    @Override
    @Save
    public Resp save(InvoiceRecipient entity) {
        //获取当前登录用工企业
        String companyId = getJwtProperty(CommonConstant.COMPANY_ID_NAME);
        entity.setCompanyId(companyId);
        return super.save(entity);
    }

    @Override
    @Update
    public Resp update(InvoiceRecipient entity) {
        return super.update(entity);
    }

    @Override
    @LogicalDel
    public Resp logicDelete(String[] ids) {
        return super.logicDelete(ids);
    }

    @GetMapping("/select_item_by_company")
    public Resp selectItemByCompany() {
        //获取当前登录代理商
        String companyId = getJwtProperty(CommonConstant.COMPANY_ID_NAME);
        return RespUtil.success(invoiceRecipientService.findByCompanyId(companyId));
    }

    @GetMapping("/find_one")
    public Resp findOne(String id) {
        return RespUtil.success(invoiceRecipientService.lambdaQuery().eq(InvoiceRecipient::getId, id).one());
    }
}
